package services.kingdee

import play.api.Logging
import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class KindeeBaseInfoSync @Inject()(
                                    materialSync: MaterialSync,
                                    employee: EmployeeInformation
                                  )(implicit ec: ExecutionContext)
  extends Logging {

  def manyOperation(accid: String, formid: String, codes: String) = formid match {
    case "item" => Future.sequence(
      codes.split(",").toSet
        .filter(f => f.nonEmpty).toSeq
        .map(
          code =>
            materialSync.operation(code)
        )
    ).map(_.flatten.mkString)
    case "employee" => Future.sequence(
      codes.split(",").toSet
        .filter(f => f.nonEmpty).toSeq
        .map(
          code =>
            employee.sync(accid = accid, code)
        )
    ).map(_.flatten.mkString)
    case _ => Future(s"formid($formid) error")
  }
}
